package com.online.music.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.music.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.online.music.service.ITypeService;
import com.online.music.entity.po.Type;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-01-31
 * @Description: type接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "type接口")
@RestController
@RequestMapping("/type")
public class TypeController {

    private final ITypeService typeService;

    @Operation(summary = "查询所有Type")
    @GetMapping
    public Result<List<Type>> findAll() {
        return Result.success(typeService.list());
    }

    @Operation(summary = "根据id查询Type")
    @GetMapping("/{id}")
    public Result<Type> findOne(@PathVariable Long id) {
        return Result.success(typeService.getById(id));
    }

    @Operation(summary = "根据分页查询Type")
    @GetMapping("/page")
    public Result<Page<Type>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Type type) {
        return typeService.findPage(pageNum, pageSize, type);
    }

    @Operation(summary = "添加或修改Type")
    @PostMapping
    public Result<Boolean> save(@RequestBody Type type) {
        return Result.success(typeService.saveOrUpdate(type));
    }

    @Operation(summary = "根据id批量删除Type")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return typeService.deleteBatch(ids);
    }

}
